package com.faradel.pharmapp.dao;

import java.util.List;
import java.util.Map;

import org.faradel.pharmapp.entities.OrderMedication;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

@Repository("orderMedicationDaoImpl")
public class OrderMedicationDaoImpl extends GenericDAOImpl<OrderMedication, Integer> implements OrderMedicationDAO
{

    @SuppressWarnings("unchecked")
    @Override
    public List<OrderMedication> findByColumn(Map<String, String> map)
    {
        Criteria criteria = this.sessionFactory.getCurrentSession().createCriteria(OrderMedication.class);
        for (Map.Entry<String, String> mapEntry : map.entrySet())
        {
            if (mapEntry.getKey().equalsIgnoreCase("medicationId") || mapEntry.getKey().equalsIgnoreCase("orderId"))
            {
                criteria.add(Restrictions.eq(mapEntry.getKey(), Integer.parseInt(mapEntry.getValue())));
            }
            else
            {
                criteria.add(Restrictions.eq(mapEntry.getKey(), mapEntry.getValue()));
            }
        }

        return criteria.list();
    }

}
